<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Swiper Image Carousel</title>
    <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
    <style>
        .swiper-container {
            width: 100%;
            height: 300px;
        }

        .swiper-slide {
            text-align: center;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .swiper-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            cursor: pointer;
            transition: transform 0.3s ease-in-out;
        }

        /* 点击图片放大的样式 */
        .swiper-slide img.enlarge {
            transform: scale(1.5);
            z-index: 9999;
        }
    </style>
</head>
<body>
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide"><img src="image1.jpg" alt="Image 1"></div>
            <div class="swiper-slide"><img src="image2.jpg" alt="Image 2"></div>
            <div class="swiper-slide"><img src="image3.jpg" alt="Image 3"></div>
            <div class="swiper-slide"><img src="image4.jpg" alt="Image 4"></div>
            <div class="swiper-slide"><img src="image5.jpg" alt="Image 5"></div>
            <div class="swiper-slide"><img src="image6.jpg" alt="Image 6"></div>
            <div class="swiper-slide"><img src="image7.jpg" alt="Image 7"></div>
            <div class="swiper-slide"><img src="image8.jpg" alt="Image 8"></div>
        </div>
        <!-- 添加左右导航按钮 -->
        <div class="swiper-button-next"></div>
        <div class="swiper-button-prev"></div>
    </div>

    <!-- Swiper.js Library -->
    <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
    <script>
        var swiper = new Swiper('.swiper-container', {
            slidesPerView: 4,
            spaceBetween: 10,
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        });

        // 点击图片放大
        document.querySelectorAll('.swiper-slide img').forEach(img => {
            img.addEventListener('click', function() {
                // 如果已经放大，点击时缩小
                if (this.classList.contains('enlarge')) {
                    this.classList.remove('enlarge');
                } else {
                    // 移除其他图片的放大状态
                    document.querySelectorAll('.swiper-slide img').forEach(image => {
                        image.classList.remove('enlarge');
                    });
                    // 给当前点击的图片添加放大类
                    this.classList.add('enlarge');
                }
            });
        });
    </script>
</body>
</html>
